﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
namespace Nirvana
{
    public class WaitLoadScene : WaitLoadAssetProgress
    {
        private AssetBundleManager abMgr;
        private string sceneName;
        private string fileName;
        private LoadSceneMode sceneMode;
        private bool IsLoad;

        public AssetBundleManager AssetBundleMgr
        {
            get { return abMgr; }
        }


        public WaitLoadScene(AssetBundleManager mgr, string sceneName, string fileName, LoadSceneMode sceneMode)
        {
            abMgr = mgr;
            this.sceneName = sceneName;
            this.fileName = Path.GetFileNameWithoutExtension(fileName);
            this.sceneMode = sceneMode;
            this.IsLoad = false;
        }

        public override float Progress
        {
            get
            {
                return 1f;
            }
        }

        public override bool keepWaiting
        {
            get
            {
                return base.Error == null && !this.IsLoad;
            }
        }


        public override bool Load()
        {
            AssetBundleItem u = this.abMgr.LoadAssetBundleItem(this.sceneName);
            if (u == null)
            {
                return true;
            }
            if (!string.IsNullOrEmpty(u.error))
            {
                base.Error = u.error;
                return false;
            }
            SceneManager.LoadScene(this.sceneName, this.sceneMode);
            IsLoad = true;
            return false;
        }
    }
}

